/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (C) 2016-2018, LomboTech Co.Ltd.
 * Author: lomboswer <lomboswer@lombotech.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#ifndef __CONFIG_PM_REG_H__
#define __CONFIG_PM_REG_H__

#include <mach/csp.h>
#include <linux/workqueue.h>
#include <linux/input.h>
#include <linux/spinlock.h>
#include <linux/notifier.h>
#ifdef CONFIG_REGULATOR_IP6103
#include <linux/regulator/consumer.h>
#endif

#if	defined(CONFIG_ARCH_LOMBO_N5V1_FPGA) || \
	defined(CONFIG_ARCH_LOMBO_N7V3_FPGA) || \
	defined(CONFIG_ARCH_LOMBO_N7V5_FPGA) || \
	defined(CONFIG_ARCH_LOMBO_N7V7_FPGA) || \
	defined(CONFIG_ARCH_LOMBO_N9V1_FPGA) || \
	defined(CONFIG_ARCH_LOMBO_N9V3_FPGA)
#define FPGA
#endif

#if defined(CONFIG_ARCH_LOMBO_N7V1)
#include "csp/n7v1/pmc_operate.h"
#elif defined(CONFIG_ARCH_LOMBO_N7V3)
#include "csp/n7v3/pmc_operate.h"
#elif defined(CONFIG_ARCH_LOMBO_N7V5) || defined(CONFIG_ARCH_LOMBO_N5V1)
#include "csp/n7v5/pmc_operate.h"
#elif defined(CONFIG_ARCH_LOMBO_N7V7)
#include "csp/n7v7/pmc_operate.h"
#elif defined(CONFIG_ARCH_LOMBO_N9V1)
#include "csp/n9v1/pmc_operate.h"
#elif defined(CONFIG_ARCH_LOMBO_N9V3)
#include "csp/n9v3/pmc_operate.h"
#endif

#define FANOUT		0
#define OUTPUT		2

#define CLK_SRC_RCOSC	0
#define CLK_SRC_LFEOSC	1

struct lombo_pmc {
	void __iomem *base;
	u32 irq;
	u32 irq_pending;
	u32 ld_irq_pending;
	u32 int_en;
	u32 pwr_wake0_enabled;
	u32 pwr_key_enabled;
	u32 sys_resetn;
	u32 key_slong_mode;
	struct input_dev *idev;
	spinlock_t lock;
	struct mutex m_lock;
	struct work_struct pmc_work;
#ifdef CONFIG_REGULATOR_IP6103
	struct regulator *ctrl0;
	struct regulator *ctrl1;
#endif
};

extern u32 lombo_get_usb_connected(void);
extern u32 lombo_get_clk_src_stat(void);

extern int register_charge_notifier(struct notifier_block *nb);
/* pmc_config_fanout_func - set LFEOSC clock fanout
 * @mode: fanout function, is 0.
 */
void pmc_config_fanout_func(u32 mode);
/* pmc_config_output_func - configure fanout as gpio output value.
 * @value: output value, 1 or 0.
 */
void pmc_config_output_func(u32 value);

#if defined(CONFIG_ARCH_LOMBO_N7V7)
void lombo_rtc_npd_handler(void __iomem *base, struct input_dev *idev);
int lombo_rtc_get_npd_state(void);
void lombo_rtc_enable_npd_int(int enable);
#endif /* CONFIG_ARCH_LOMBO_N7V7 */

#endif
